import Vue from "vue";
import Vuex from "vuex";
import api from "../api/index";
Vue.use(Vuex);

//创建一个store仓库
const store = new Vuex.Store({
  //state用来存放数据的对象
  state: {
    //初始值、存放的东西
    admin: "111",
    core: 0,
    isLogin: false,
    showLogin: false,
    showActivity: false,
    navshow: true
  },
  mutations: {
    //专门负责修改state中的变量
    //不能放异步
    setAdmin(state, admin) {
      state.admin = admin;
    },
    setIsLogin(state, value) {
      state.isLogin = value;
    },
    show(state, bool) {
      //登录
      state.showLogin = bool;
    },
    hide(state, bool) {
      state.showLogin = bool;
    },
    showhd(state, bool) {
      state.showActivity = bool;
    },
    hidehd(state, bool) {
      state.showActivity = bool;
    },
    //daohang
    setIsnavshow(state, bool) {
      state.navshow = bool;
    },
    setIsnavhide(state, bool) {
      state.navshow = bool;
    }
  },
  actions: {
    //专门发送异步ajax请求，从服务器端获取数据
    isAdmin({ commit }) {
      commit("setAdmin", true);
    },
    isLoGin({ commit }) {
      commit("setIsLogin", true);
    },
    isShow({ commit }) {
      commit("show", true);
    },
    isHide({ commit }) {
      commit("hide", false);
    },
    hdShow({ commit }) {
      commit("showhd", true);
    },
    hdHide({ commit }) {
      commit("hidehd", false);
    },
    nav_Show({ commit }) {
      commit("setIsnavshow", true);
    },
    nav_Hide({ commit }) {
      commit("setIsnavhide", false);
    }
  }
});

export default store;
